package tasks;

import java.util.concurrent.LinkedBlockingQueue;

import tools.Format;

import core.Message;
import core.MessageQueue;


public class ProcessMessageQueue implements Runnable {
	private LinkedBlockingQueue<Message> messageQueue;

	public ProcessMessageQueue() {
		this.messageQueue = MessageQueue.getMessageQueue();
	}

	@Override
	public void run() {
		Message message = null;

		do {
			try {
				message = this.messageQueue.take();	
				byte[] themessage = message.generate();
				message.getOutput().write(themessage);			
			} catch (InterruptedException e) {
				System.out.println("ProcessMessageQueue|InterruptedException: "+e);
			} catch (Exception e) {
				System.out.println("ProcessMessageQueue|Exception: "+e);
			}
		} while(true);		
	}
}
